package com.ckx.blog.controller;

import com.ckx.constants.SystemConstants;
import com.ckx.domain.ResponseResult;
import com.ckx.domain.dto.AddCommentDto;
import com.ckx.domain.entity.Comment;
import com.ckx.domain.vo.PageVo;
import com.ckx.service.CommentService;
import com.ckx.utils.BeanCopyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@Api(value = "评论接口")
@RestController
@RequestMapping("/comment")
public class CommentController {

    @Autowired
    private CommentService commentService;

    @GetMapping("/commentList")
    public ResponseResult commentList(Long articleId, Integer pageNum, Integer pageSize) {
        PageVo pageVo = commentService.commentList(SystemConstants.ARTICLE_COMMENT, articleId, pageNum, pageSize);
        return ResponseResult.okResult(pageVo);
    }

    @PostMapping
    @ApiOperation(value = "添加评论", notes = "就是添加评论，描述啥？")
    public ResponseResult addComment(@RequestBody AddCommentDto addCommentDto) {
        Comment comment = BeanCopyUtil.copyBean(addCommentDto, Comment.class);
        commentService.addComment(comment);
        return ResponseResult.okResult();
    }

    @GetMapping("/linkCommentList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "当前页面"),
            @ApiImplicitParam(name = "pageSize", value = "页大小")
    })
    public ResponseResult linkCommentList(Integer pageNum, Integer pageSize) {
        PageVo pageVo = commentService.commentList(SystemConstants.LINK_COMMENT, null, pageNum, pageSize);
        return ResponseResult.okResult(pageVo);
    }

}
